package cn.wolfcode.jedis;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisTestHash {
    @Test
    public void test(){
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        /*设置密码
	    jedis.auth("");*/
        // 3:TODO


        //hash类型
        /*存入一个hash对象
        jedis.hset("users1","name","wangwu");
        jedis.hset("users1","age", String.valueOf(19));
        根据hash对象键取去值
        System.out.println(jedis.hget("users1", "name"));
        System.out.println(jedis.hget("users1", "age"));*/

        /*判断hash对象是含有某个键
        System.out.println(jedis.hexists("users1", "name"));
        System.out.println(jedis.hexists("users1", "age"));*/

        /*根据hashkey删除hash对象键值对
        jedis.hdel("users1","name");
        System.out.println(jedis.hget("users1", "name"));*/


        // 4:关闭资源
        jedis.close();
        pool.destroy();
    }
}
